<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search :config='searchConfig' @search='search' @getHeight='getHeight'/>
    <!-- table区域-begin -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-90'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config='tableToolbar'
        :checkbox-config='checkboxConfig'
        v-bind='vexConfig'
        @checkbox-change='selectChangeEvent'
        @checkbox-all='selectChangeEvent'
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click='handleAdd' v-has="'terminal:add'" type='primary'>新增</a-button>
            <a-button type="primary" @click="startorstop(1)">启用</a-button>
            <a-button type="primary" @click="startorstop(0)">停用</a-button>
            <a-button v-has="'terminal:delete'" @click='batchDel'>删除</a-button>
          </div>
        </template>
        <template #avatarslot='{ row }'>
          <viewer :images='[row.avatar]'>
            <a-avatar shape='square' size='small' :src='row.avatar' icon='user' />
          </viewer>
        </template>
        <template #status='{ row,rowIndex }'>
          <a-switch :checked='row.status' size='small' @change='handleStatus(row,$event)' />
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.terminalCode }}</a>
        </template>
        <template #isLeader='{ row }'>
          {{ row.isLeader == 0 ? '是' : '否' }}
        </template>
        <div slot='isActiveStatus' slot-scope='text,recode'>
          {{ text|isActiveStatus }}
        </div>
        <div slot='filterTerminalType' slot-scope='text,recode'>
          {{ text|filterTerminalType }}
        </div>

        <template #action='{ row:record }'>
          <a v-has="'terminal:update'" @click='handleEdit(record)'>编辑</a>
          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多
              <a-icon type='down' />
            </a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a href='javascript:' @click='handleConfigTer(record)'>门店配置</a>
              </a-menu-item>
              <a-menu-item v-has="'business:log'">
                <a href='javascript:' @click='handleBusiness("门店管理",record)'>日志</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>

        <template #pager>
          <vxe-pager :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
                     :currentPage.sync='ipagination.current' :page-size.sync='ipagination.pageSize'
                     :total='ipagination.total'
                     :pageSizes='ipagination.pageSizeOptions' @page-change='handlePageChange'>
          </vxe-pager>
        </template>

        <template #avatarslot='{ row }'>
          <viewer :images='[row.avatar]'>
            <a-avatar shape='square' size='small' :src='row.avatar' icon='user'/>
          </viewer>
        </template>
        <template #status="{ row,rowIndex }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event)"/>
        </template>
        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.terminalCode }}</a>
        </template>
        <template #action='{ row:record }'>
          <a v-has="'terminal:update'" @click='handleEdit(record)'>编辑</a>
        </template>
        <template #url='{ row }'>
          <viewer :images='row.url'>
            <a-avatar shape='square'  :src='row.url' icon='user'/>
          </viewer>
        </template>

        <template #pager>
          <vxe-pager :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
                     :currentPage.sync='ipagination.current' :page-size.sync='ipagination.pageSize'
                     :total='ipagination.total'
                     :pageSizes='ipagination.pageSizeOptions' @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <Modal ref="modalForm" @ok="modalFormOk"></Modal>
  </a-card>
</template>

<script>
import Modal from './modules/RotationModal'
import {doReleaseData, doReovkeData} from '@/api/api'
import {getAction} from '@/api/manage'
import {PageListMixin} from '@/mixins/PageListMixin'

export default {
  name: "RotationList",
  mixins: [PageListMixin],
  components: {
    Modal,
  },
  data() {
    return {
      description: '轮播管理页面',
      // 查询条件
      searchConfig: [
        {
          type: 'input',
          name: 'carouselType',
          placeholder: '搜索类型'
        },
      ],
      // 表头
      columns: [
       {
         type: 'checkbox',
         maxWidth: 60,
         fixed: 'left'
        },
        {
          title: '图片',
          minWidth: 80,
          field: 'url',
          slots: { default: 'url' }
        },
        {
          title: '描述',
          minWidth: 80,
          field: 'remarks'
        },
        // {
        //   title: '类型',
        //   minWidth: 80,
        //   field: 'carouselType'
        // },
        {
          title: '状态',
          minWidth: 80,
          field: 'status',
          slots: { default: 'status' }
        },
        {
          title: '操作',
          field: 'action',
          minWidth: 80,
          slots: {default: 'action'}
        }
      ],
      url: {
        list:  window._CONFIG['domianURL'] +"/cnCarouselController/getPageList",
        delete:  window._CONFIG['domianURL'] +"/cnCarouselController/deleteById",
        deleteBatch:  window._CONFIG['domianURL'] + "/cnCarouselController/deleteBatch",
        enable: window._CONFIG['domianURL'] +'/cnCarouselController/invoke',
        disable: window._CONFIG['domianURL'] +'/cnCarouselController/blockUp',
        startOrStopUrl: window._CONFIG['domianURL'] + '/cnCarouselController/updateStatus',
      },
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
  methods: {
    startorstop: function(status) {
      if (!this.url.startOrStopUrl) {
        this.$message.error('请设置url启用停用!')
        return
      }
      if (this.selectedRowKeys.length <= 0) {
        this.$message.warning('请选择一条记录！')

      } else {
        var ids = ''
        for (var a = 0; a < this.selectedRowKeys.length; a++) {
          ids += this.selectedRowKeys[a] + ','
        }
        var that = this
        this.$confirm({
          title: '确认修改',
          content: '是否修改选中数据?',
          onOk: function() {
            that.loading = true
            getAction(that.url.startOrStopUrl, { ids: ids, status: status }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
                that.onClearSelected()
              } else {
                that.$message.warning(res.message)
              }
            }).finally(() => {
              that.loading = false
            })
          }
        })
      }
    },

    //执行发布操作
    releaseData: function (id) {
      console.log(id);
      var that = this;
      doReleaseData({id: id}).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.loadData(1);
        } else {
          that.$message.warning(res.message);
        }
      });
    },
    //执行撤销操作
    reovkeData: function (id) {
      var that = this;
      doReovkeData({id: id}).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.loadData(1);
          this.syncHeadNotic(id)
        } else {
          that.$message.warning(res.message);
        }
      });
    },
    syncHeadNotic(anntId) {
      getAction("sys/annountCement/syncNotic", {anntId: anntId})
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>

